# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

EAPI=1
inherit eutils findlib

DESCRIPTION="ocamlgraph is a graph library for Objective Caml"
HOMEPAGE="http://ocamlgraph.lri.fr/"
SRC_URI="http://ocamlgraph.lri.fr/download/${P}.tar.gz"

LICENSE="GPL2"
SLOT="0"
KEYWORDS="x86"

IUSE="doc examples gtk +ocamlopt"
DEPEND="
	dev-ml/findlib
	dev-ml/lablgtk
"
RDEPEND="${DEPEND}"

src_compile() {
	econf || die
	emake -j1 byte || die

	if use ocamlopt; then
		emake -j1 opt || die
	fi

	emake -j1 dgraph
	emake -j1 viewer

	if use doc; then
		emake -j1 doc
	fi

	if use gtk; then
		emake -j1 editor
	fi
}

src_install() {
	findlib_src_preinst
	emake install-findlib || die

	if use ocamlopt; then
		newbin dgraph/dgraph.opt ocamlgraph_dgraph
	else
		newbin dgraph/dgraph.byte ocamlgraph/dgraph
	fi

	if use gtk; then
		if use ocamlopt; then
			newbin editor/editor.opt ocamlgraph_editor
		else
			newbin editor/editor.byte ocamlgraph_editor
		fi
	fi

	if use ocamlopt; then
		newbin view_graph/viewgraph.opt ocamlgraph_viewer
	else
		newbin view_graph/viewgraph.byte ocamlgraph_viewer
	fi

	dodoc README CREDITS FAQ CHANGES || die
	if use doc; then
		dohtml doc/*
	fi

	if use examples; then
		insinto /usr/share/doc/${PF}
		doins -r examples
	fi
}
